<?php
/* Query to get the result for the pages */
$query = ' SELECT name, published_date, id FROM pages ';
$result = mysql_query($query);

/* To delete them */
if(isset($_GET['task']) && $_GET['task'] == 'delete')
{
	$query = 'DELETE FROM pages WHERE id = '.$_GET['id'].' LIMIT 1';
	mysql_query($query);
	header('location:index.php?page=listing&sm=Page deleted successfully'); exit;
}

?>
<h2>Listing Page</h2>
<?php if(!empty($_GET['sm'])) { ?>
<div class="success"><?php echo $_GET['sm']; ?> </div>
<?php } ?>
<table cellpadding="2" cellspacing="2" border="0" width="700" style="background-color:#000000;">
		<tr style="background-color:#FFFFFF;">
			<td class="label">S.No</td>
			<td class="label">Page Name</td>
			<td colspan="3" class="label">Tasks</td>
		</tr>
<?php $count = 1; 
	if( mysql_num_rows($result) > 0)
	{
		while($row = mysql_fetch_array($result))
		{
	?>
	<tr style="background-color:#FFFFFF;">
		<td><?php echo $count++; ?></td> 
		<td><?php echo $row['name']; ?></td>
		<td><a href="index.php?page=edit_content&id=<?php echo $row['id']; ?>">Edit</a></td>
		<td><a onclick="return confirm('Are you sure you would like to delete this page?');" href="index.php?page=listing&task=delete&id=<?php echo $row['id']; ?>">Remove</a></td>
	</tr>		
<?php 
		}
	}
	else
	{
		?>
		<tr style="background-color:#FFFFFF;">
			<td colspan="6">No pages found</td>
		</tr>
		<?php
	}
?>	
</table>